package com.leetcode;

/**
 * @author fy
 * @date 2022/3/29 10:52
 */
public class Solution278 {

    /**
     * 278. 第一个错误的版本
     *
     * @param n
     * @return
     */
    public int firstBadVersion(int n) {
        int l = 1;
        int r = n;
        while (l < r) {
            int mid = l + (r - l) / 2;
            if (isBadVersion(mid)) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        return l;
    }

    public int firstBadVersion1(int n) {
        return firstBad(1, n);
    }

    public int firstBad(int l, int r) {
        if (l >= r) {
            return l;
        }
        int mid = l + (r - l) / 2;
        boolean res = isBadVersion(mid);
        if (res) {
            return firstBad(l, mid);
        } else {
            return firstBad(mid + 1, r);
        }
    }

    private boolean isBadVersion(int version) {
        return false;
    }
}
